package com.chuck.learning.solutions;

import cn.hutool.core.lang.Console;

public class 二维数组中查找元素 {

    public static void main(String[] args) {
        int[][] matrix={
                {1,3,5},
                {2,4,8},
                {10,11,13}
        };
        //查找11  5-> 8 ->13 ->11
        int row = 0; int column = matrix[0].length-1;

        //要查找的数字
        int num = 11;
        while (row<matrix.length&& column>=0){
            int value = matrix[row][column];
            if (num > value) {
                row++;
            } else if (value == num) {
                Console.log("找到了:"+row+"__"+column);
                break;
            } else {
                column --;
            }
        }
        Console.log("没有找到");
    }
}
